/**
 * Created by chang on 2017/5/25.
 */
import menus from '../../static/menus.json'
import { deepCopy } from '../assets/utils/util'

const state = {
  userInfo: {}
}
const defaultValue = deepCopy(state)

const getters = {
  userInfo: state => {
    return state.userInfo
  }
}
const actions = {
  Login () {
    return new Promise((resolve) => {
      // 登录成功之后，取用户权限，并自动将 '首页' 填充到tab
      window.$globalHub.$store.commit('SET_USERNAV', menus)
      resolve()
    })
  }
}
const mutations = {
  // 初始化
  USER_INIT () {
    window.$globalHub.$store.state.login = defaultValue
  },
  // 设置登录持久化
  SET_AUTH_INFO: (state, val) => {
    state.userInfo = val
  }
}
export default {
  state,
  getters,
  mutations,
  actions
}
